package com.yuanfeng.action.front.buy.dao;
import com.yuanfeng.pojo.Books;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class BookSearchDaoImpl extends HibernateDaoSupport implements BookSearchDao {
	/**
	 * 图书Book对象
	 */
	private Books book;

	/**
	 * 搜索图书
	 * @param bookName
	 * @return
	 */
	@Override
	public Books searchBook(String bookName) {

		String hql = " from Books where name=?";
		Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hql);
		query.setParameter(0,bookName);
		Books book = (Books)query.uniqueResult();
		System.out.println(book);

		if(book != null)
			//返回查询到的图书对象
			return book;
		else
			return null;
	}

}
